package com.topvision.controller.glass;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.topvision.model.glass.Launcher;
import com.topvision.service.glass.LauncherService;
import com.topvision.util.PageUtils;
import com.topvision.util.Query;
import com.topvision.util.R;
import com.topvision.controller.AbstractController;

/**
 * 桌面管理
 *
 * @author jack
 * @email 791127866@qq.com
 * @date 2017-10-10 15:31:37
 */
@RestController
@RequestMapping("glass/launcher")
public class LauncherController extends AbstractController {
    @Autowired
    private LauncherService launcherService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("glass/launcher:list")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);

        List<Launcher> launcherList = launcherService.queryList(query);
        int total = launcherService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(launcherList, total, query.getLimit(), query.getPage());

        return R.success().put("page", pageUtil);
    }

    @RequestMapping("/findListByParam")
    @RequiresPermissions("glass/launcher:list")
    public R findListByParam(@RequestParam Map<String, Object> params){

        List<Launcher> launcherList = launcherService.queryByParam(params);

        return R.success().put("launcherList", launcherList);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("glass/launcher:info")
    public R info(@PathVariable("id") Integer id){
        Launcher launcher = launcherService.queryObject(id);
        return R.success().put("launcher", launcher);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("glass/launcher:save")
    public R save(@RequestBody Launcher launcher){
		launcherService.save(launcher);
        return R.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("glass/launcher:update")
    public R update(@RequestBody Launcher launcher){
		launcherService.update(launcher);
        return R.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("glass/launcher:delete")
    public R delete(@RequestBody Integer[] ids){
		launcherService.deleteBatch(ids);
        return R.success();
    }

}
